using System;
using System.Collections.Generic;
using System.Text;
using NBusiness.CodeDom;
using NBusiness.ESharp.Compiler;
using NBusiness.CodeDom.Compiler;

namespace NBusiness.ESharp
{
    [Serializable]
    public class ESharpUsing : EntityUsing
    {
        protected override void Attach()
        {
        }

        protected override void InitializeAssignmentLogic()
        {
            Assignments.Add(new AssignmentLogic(
                ESharpEntityElementTypes.UsingType,
                new AssignmentLogicHandler(AssignUsingType) ));

            Assignments.Add(new AssignmentLogic( ESharpEntityElementTypes.UsingTypeJoin ));

            Assignments.Add(new AssignmentLogic( 
                ESharpEntityElementTypes.StatementEnd,
                PostAssignmentAction.Stop ));

            Assignments.Add(new AssignmentLogic( ESharpEntityElementTypes.WhiteSpace ));
            Assignments.Add(new AssignmentLogic( ESharpEntityElementTypes.Comment ));
        }

        private void AssignUsingType(object sender, AssignmentLogicEventArgs e)
        {
            Namespace = (Namespace == null ?
                e.Elements.Peek().Value :
                Namespace + "." + e.Elements.Peek().Value);
        }
    }
}
